/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>短信配置模板</h3>
        <h5>短信平台短信配置模板</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>短信配置模板, 由平台设置管理.</li>
          <li>添加/编辑模板时注意"短信签名"、"短信内容"的填写.</li>
          <li style="color:red">当添加了所有短信场景时，无法继续新增模板.</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>模板列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <div class="add" @click="toEdit()">
          <span>
            <i class="el-icon-circle-plus" /> 新增模板
          </span>
        </div>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
    </div>
    <div class="tablebox">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="应用场景" prop="send_scene_detail" width="150" show-overflow-tooltip></el-table-column>
        <el-table-column label="短信签名" prop="sms_sign" width="100"></el-table-column>
        <el-table-column label="短信模板" prop="sms_tpl_code" width="150"></el-table-column>
        <el-table-column label="发送短信的内容" prop="tpl_content" width="500"></el-table-column>
        <el-table-column label="修改时间" prop="start_time_show" width="180"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button
                size="small"
                @click="toEdit(scope.row.tpl_id)"
                icon="el-icon-edit-outline"
              >编辑</el-button>
              <el-button size="small" @click="remove(scope.row.tpl_id)" icon="el-icon-delete">删除</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      cat_id: null,
      title: null,
      isAddAllScene: false
    };
  },
  created() {
    this.getPage();
    this.getIsAddAllScene();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      this.request
        .get("/user/sms_template/page", {
          params: {
            page: that.currentPage,
            size: that.pageSize
          }
        })
        .then(function(res) {
          that.tableData = res.records;
          that.totalCount = res.total;
        });
    },
    getIsAddAllScene() {
      var that = this;
      this.request.get("user/sms_template/send_scene").then(function(res) {
        that.isAddAllScene = res.length == 0;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    remove(id) {
      var that = this;
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          that.request.delete("/user/sms_template/" + id).then(function(res) {
            if (res.status == 1) {
              that.$message.success("删除成功!");
              that.getPage();
              that.getIsAddAllScene();
            }
          });
        })
        .catch(() => {
          that.$message.info("已取消删除");
        });
    },
    toEdit(id) {
      //新增时检查是否添加了所有场景
      if (!id && this.isAddAllScene) {
        this.$message.success("已添加了所有短信场景，没得加了");
        return;
      }
      this.$router.push({
        name: "sms_tpl_detail",
        params: {
          id: id,
          currentPage: this.currentPage
        }
      });
    }
  }
};
</script>

<style scoped>
</style>
